package com.jeespring.rocketmq.simple.sync;

import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @description Producer
 * @author 张朝阳
 * @date 2021/9/13 23:36:12
 */
public class Producer {
    public static void main(String[] args) throws Exception {

        DefaultMQProducer producer = new DefaultMQProducer("producer-group");
        producer.setNamesrvAddr("192.168.19.10:9876");
        producer.start();

        for (int i = 0; i < 10; i++) {
            //public Message(String topic, String tags, byte[] body)
            String msg = "同步消息-" + i;
            Message message = new Message("simple-message","sync",msg.getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(message);
            System.out.println(JSON.toJSONString(sendResult));
        }

        producer.shutdown();
    }
}
